/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package platform;

import Utils.ByteArrayConverter;
import java.security.InvalidParameterException;
import zorg.platform.LongSortedVector;
import zorg.platform.Utils;

/**
 *
 * @author Tomasz Nowak
 */
public class TenorUtils implements Utils
{
	@Override
	public boolean equals( byte[] array1, int offset1, byte[] array2, int offset2, int length )
	{
		if ( array1.length - offset1 < length || array2.length - offset2 < length )
		{
			throw new InvalidParameterException("array size");
		}

		for ( int i = 0; i < length; ++i )
		{
			if ( array1[i + offset1] != array2[i + offset2] )
			{
				return false;
			}
		}
		return true;
	}

	@Override
	public String byteToHexString( byte[] buffer, int offset, int length )
	{
		return ByteArrayConverter.toString(buffer, offset, length);
	}

	@Override
	public String byteToHexString( byte[] buffer )
	{
		return byteToHexString(buffer, 0, buffer.length);
	}

	public static String bufferToHex( byte[] buffer )
	{
		return ByteArrayConverter.toString(buffer);
	}

	@Override
	public int getInt( byte[] data, int begin, int end )
	{
		int result = 0;
		for ( int i = 0; i < 4 && i < end - begin; ++i )
		{
			result <<= 8;
			result |= data[end - i - 1];
		}
		return result;
	}

	@Override
	public void zero( byte[] data )
	{
		for ( int i = 0; i < data.length; ++i )
		{
			data[i] = 0;
		}
	}

	@Override
	public byte[] copy( byte[] data )
	{
		byte[] copy = new byte[data.length];
		for ( int i = 0; i < copy.length; i++ )
		{
			copy[i] = data[i];
		}
		return copy;
	}

	@Override
	public LongSortedVector createSortedVector()
	{
		return new TenorLongSortedVector();
	}

}
